
public class quicksort {
	//public static void swap(int a,int b){
	//int tmp= a;
	//a = b;
		//b = tmp;
	//}
	public static void QuickSort(int A[], int p,int r){
		int i; int j; int x;
			i=p;
			j=r;
			x=A[(i+j)/2];
			do
			{
			while(A[i]<x) i++;
			while(A[j]>x) j--;
			if(i<=j)
			{
				int tmp = A[i];
				A[i] = A[j];
				A[j] = tmp;
				
			
			i++;
			j--;
			}
			}
			while(i<=j);
			if(j>p)
			QuickSort(A,p,j);
			if(i<r)
			QuickSort(A,i,r);
			}
			
	 
		// TODO Auto-generated method stub
		
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int []mas = new int [1000000];
		int L = 0;
		int H = mas.length - 1;
		System.out.printf("Random massive:\n");
		for(int i = 0; i < mas.length; i++){
			mas[i] = (int) Math.round(Math.random()*100000000);
			//System.out.print(mas[i] + " ");
	}
		System.out.println();
		long startTime = System.currentTimeMillis();
		QuickSort(mas, L, H );
		long timeSpent = System.currentTimeMillis() - startTime;
		for(int i=0; i< mas.length; i++){
		//System.out.print(mas[i] + " ");
			}
		System.out.println("\nProgram time- " + timeSpent);
}
}
